package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.bean.LendingBean;
import com.shd.edanpei.presenter.contract.SureLoanInfocontract;
import com.shd.edanpei.presenter.SureLoanInfoPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 填写收款信息
 */
public class SureLoanInfoActivity extends BaseActivity<SureLoanInfoPresenter>
        implements SureLoanInfocontract.SureLoanInfoIView {


    @BindView(R.id.headline)
    TextView tvHeadLine;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_bankname)
    EditText etBankName;
    @BindView(R.id.et_bankcard)
    EditText etBankCard;
    @BindView(R.id.et_branch)
    EditText etBranch;
    @BindView(R.id.et_phone)
    EditText etPhone;

    private int orderId;
    private Bundle bundle;

    @Override
    protected int setLayout() {
        return R.layout.activity_loaninfo;
    }

    @Override
    protected SureLoanInfoPresenter bindPresenter() {
        return new SureLoanInfoPresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        tvHeadLine.setText("提供审核信息");
        bundle = getIntent().getExtras();
        orderId = bundle.getInt(Constant.ORDER_ID);
        mPresenter.getLendingInfo(orderId);
    }

    @Override
    protected void initListener() {
        etName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setName(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etBankName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setBankName(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etBankCard.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setBankCard(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etBranch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setBankBranch(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etPhone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                mPresenter.setPhone(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    public void setLendingInfo(LendingBean bean) {
        etName.setText(bean.getName());
        etBankName.setText(bean.getBankName());
        etBankCard.setText(bean.getBankCard());
        etBranch.setText(bean.getOpenAccountBank());
        etPhone.setText(bean.getPhone());
    }

    @OnClick(R.id.tv_submit)
    void submit() {
        mPresenter.submitLendingInfo(orderId,bundle);
    }

    @OnClick(R.id.iv_headline_back)
    void close() {
        finish();
    }


}
